﻿using BasicModuleWebApiAuthorization.DbConext;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace BasicModuleWebApiAuthorization.Controllers
{
    [Route("api/[controller]/UserPermission")]
    [ApiController]
    public class UserPermissionController : ControllerBase
    {
        public MysqlDBContext mysqlDBContext;

        public UserPermissionController(MysqlDBContext mysqlDBContext)
        {
            this.mysqlDBContext = mysqlDBContext;
        }

        [HttpPost]
        public void UserPermission([FromBody] UserPermission userPermission)
        {
            mysqlDBContext.userPermissions.Add(userPermission);
            mysqlDBContext.SaveChanges();
        }

        [Authorize("User")]
        [HttpGet]
        public List<UserPermission> GetPermission()
        {
            List<UserPermission> userPermissions = mysqlDBContext.userPermissions.ToList();
            return userPermissions;
        }

        /// <summary>
        /// 用户健全
        /// </summary>
        [HttpGet("UserPermission")]
        public void UserPermission() 
        {
        
        }
    }
}
